package com.huawei.cloud.phone.management.application.user.dto;

import com.huawei.cloud.phone.management.domain.user.User;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;

@Data
public class UserDTO {
    /**
     * 用户名
     */
    @NotNull(message = "username不能为空，长度必须是6-18位")
    @Length(min = 6, max = 18, message = "username不能为空，长度必须是6-18位")
    private String username;

    /**
     * 用户密码
     */
    @NotNull(message = "password不能为空，长度必须是9-18位")
    @Length(min = 9, max = 18, message = "password不能为空，长度必须是9-18位")
    private String password;

    /**
     * 转换成用户数据数据
     *
     * @return 用户模型数据
     */
    public User toUser() {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        return user;
    }
}
